home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2776 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Can be C a so strange language ???. Problem with a function returning a pointer...
  5. Date: Tue, 23 Jan 96 21:02:00 GMT
  6. Organization: none
  7. Message-ID: <822430920snz@genesis.demon.co.uk>
  8. References: <4e015j$drt@hermes.fundp.ac.be> <822324787snz@genesis.demon.co.uk> <4e2pri$pk9@nntpd2.cxo.dec.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4e2pri$pk9@nntpd2.cxo.dec.com>
  15.            b_hibbert@csc32.enet.dec.com "Brian Hibbert" writes:
  16.  
  17. >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  18. >
  19. >>This looks rather convoluted and appears to go into an infinite loop if it
  20. >>hits the end of the list. Maybe you wanted something like:
  21. >>
  22. >>{
  23. >>    while (position_ptr != NULL && position_ptr->res_number != residue_number)
  24. >>        position_ptr = position_ptr->cooh_ptr;
  25. >>
  26. >>    return position_ptr;
  27. >>}
  28. >
  29. >I had almost posted an identical routine, but I decided to move the 
  30. >comparison of the residue_number outside the while test condition.  If 
  31. >the position_ptr is NULL and if the right side of the && operator is 
  32. >evaluated first, the code will cause a segmentation fault or access 
  33. >violation on some architectures.  Not knowing the system that this will 
  34. >be run on, and not knowing the order that the compiler does the 
  35. >evaluation, I think it's best to err on the side of caution.
  36.  
  37. The code is correct because && enforces order of evaluation and
  38. short-circuiting.
  39.  
  40. Please, if you post a response please don't email it as well (unless
  41. somebody asked for that). I've already emailed a reply to this and prefer
  42. not to have to answer the same thing twice. If you do post and email, make
  43. that clear in the email.
  44.  
  45. -- 
  46. -----------------------------------------
  47. Lawrence Kirby | fred@genesis.demon.co.uk
  48. Wilts, England | 70734.126@compuserve.com
  49. -----------------------------------------
  50.